<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        img{
            vertical-align: top;
        }

        li {
            list-style: none;
        }

        .wrap {
            width: 1226px;
            margin: 0 auto;
            margin-top: 50px;
            position: relative;
        }

        .wrap .dotBar {
            position: absolute;
            right: 50px;
            bottom: 20px;
            display: flex;
            text-align: center;
            line-height: 45px;
            z-index: 999;
        }

        .wrap .dotBar li {
            flex: 1;
            width: 6px;
            height: 6px;
            border-radius: 50%;
            background-color: #fff;
            border: 2px solid hsla(0,0%,100%,.3);
            font-size: 0;
            margin: 0 4px;
        }
        .wrap .dotBar .active{
            background-color: rgba(0, 0, 0,0.4);
            color: #fff;
        }
       
        .tabBar{
           
        }
        .tabBar li{
            width: 100%;
            background-color: #6ff;
            text-align: center;
            display: none;
        }
        .tabBar li img{
            width: 100%;
        }
        .tabBar .show{
            display: block;
        }
        
    </style>
</head>

<body>
    <div class="wrap">
        <!-- dot -->
        <ul class="dotBar">
            <li class="active">item_01</li>
            <li>item_02</li>
            <li>item_03</li>
            <li>item_04</li>
            <li>item_05</li>
        </ul>
        <ul class="tabBar">
            <li class="show"><img src="../images/1.jpg" alt=""></li>
            <li><img src="../images/2.jpg" alt=""></li>
            <li><img src="../images/3.webp" alt=""></li>
            <li><img src="../images/4.webp" alt=""></li>
            <li><img src="../images/5.jpg" alt=""></li>
        </ul>
    </div>
</body>
<script>
    // 简易轮播
    // (1)  点击切换
    // (2)  自动轮播
    // (3)  移入暂停 移出启动

    
    var liList = document.querySelectorAll(".dotBar li");
    var tabList = document.querySelectorAll(".tabBar li");

    var index = 0; // 全局变量 (记录轮播的下标)

    for (let i = 0; i < liList.length; i++) { // 循环绑定事件(页面加载时)
        let li = liList[i];
        li.onclick = function () {
            console.log(i);
            index = i; //点击时更新index (记录当前元素的下标 => 下次轮播从当前开始)

            // 先清除集合中所有元素的样式
            for(var j=0;j<liList.length;j++){  // 点击时 遍历集合有元素 
                liList[j].className = "";  // 清空导航liList的样式
                tabList[j].className = ""; // 清空 =>  tabList的样式
            }

            liList[i].className = "active";  // 当前元素 变为活跃状态
            tabList[i].className = "show";   // 对应下标的tab盒子显示
        }
    }

    var timer = setInterval(function(){
        index++;
        if(index >= liList.length){
            index = 0;
        }

        console.log(index);
        for(var j=0;j<liList.length;j++){  // 点击时 遍历集合有元素 
            liList[j].className = "";  // 清空点 liList的样式
            tabList[j].className = ""; // 清空 =>  tabList的样式
        }
        liList[index].className = "active";      // 对应下标的点 变为活跃状态
        tabList[index].className = "show";   // 对应下标的tab盒子显示
    },3000);

  


</script>

</html>